<link type="text/css" rel="stylesheet" href="<?php echo $this->basePath('public/css/dbblack/css/ucenter.css'); ?>" />
<link type="text/css" rel="stylesheet" href="<?php echo $this->basePath('public/css/dbblack/css/product.css'); ?>" />

<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/artdialog/artDialog.js?skin=simple'); ?>"></script>
<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/artdialog/plugins/iframeTools.js'); ?>"></script>
<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/jquery.validate.js'); ?>"></script>
<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/jquery.form.js'); ?>"></script>
<style type="text/css">
    .error {
        color: #ff3300;
        display: inline-block;
        padding: 3px 5px;
        position: relative;
        text-align: left;
        top: 1px;
    }
    .error.validate_right {
        color: #009900;
        display: inline-block;
        padding: 3px 5px;
        position: relative;
        text-align: left;
        top: 1px;
    }
</style>
<div class="container clearfix">
    <?php echo $this->partial('shopfront/home/left_menu.phtml'); ?>
    <?php
    $yezfInfo  = $this->frontwebsite()->websitePaymentInfo('yezf');
    $yezfState = 0;
    if(isset($yezfInfo['paycheck_state']['checked']) and $yezfInfo['paycheck_state']['checked'] == 1) $yezfState = 1;
    ?>
    <div class="uc-content">
        <h1 class="title"><span><?php echo $this->translate('账户余额'); ?>：</span></h1>
        <form class="form-search" style="margin: 0;" method="get">
        <div class="box p15 mt10 clearfix">
            <?php echo $this->translate('账户余额'); ?>：<b class="red f18"><?php echo $this->frontwebsite()->shopPriceExtend($this->user_info->user_money); ?></b>
            <span class="fr">
                <input type="text" name="search_content" id="search_content" style="height: 20px;width: 300px;" value="<?php echo isset($_GET['search_content']) ? $this->escapehtml($_GET['search_content']) : ''; ?>" placeholder="<?php echo $this->translate('输入金额或备注信息'); ?>">&nbsp;
                <button type="submit" class="btn btn-main btn-mini"><?php echo $this->translate('搜索'); ?></button>
            </span>
        </div>
        </form>
        <div class="order-menu">
            <ul class="tab-head">
                <?php echo $this->partial('shopfront/home/home-money-menu.phtml'); ?>
                <li style="float: right;width: 200px;text-align: right;">
                    <?php if($yezfState == 1) { ?>
                    <a href="javascript:;" onclick="my_pay_to();" class="btn btn-primary btn-mini"><?php echo $this->translate('充值'); ?></a>
                    &nbsp;&nbsp;
                    <?php } ?>
                    <a href="javascript:;" class="btn btn-main btn-mini" onclick="money_oper();"><?php echo $this->translate('提现'); ?></a>
                </li>
            </ul>
        </div>
        <?php if ($this->user_paycheck_log->getTotalItemCount() > 0) {
            $type_array = array(1=>$this->translate('充值'), 2=>$this->translate('消费'), 3=>$this->translate('提现'), 4=>$this->translate('退款'));
            ?>
        <table class="simple">
            <tr>
                <th width="120"><?php echo $this->translate('时间'); ?></th>
                <th width="60"><?php echo $this->translate('充值金额'); ?></th>
                <th width="80"><?php echo $this->translate('支付方式'); ?></th>
                <th width="60"><?php echo $this->translate('状态'); ?></th>
                <th width="60"><?php echo $this->translate('操作者'); ?></th>
                <th width="120"><?php echo $this->translate('完成时间'); ?></th>
                <th width="240"><?php echo $this->translate('备注'); ?></th>
            </tr>
            <?php foreach ($this->user_paycheck_log as $log_value) { ?>
                <tr>
                    <td><?php echo date("Y-m-d H:i:s", $log_value['paycheck_time']); ?></td>
                    <td><?php echo $this->frontwebsite()->shopPrice($log_value['money_change_num']); ?></td>
                    <td><?php echo !empty($log_value['pay_name']) ? $log_value['pay_name'] : $this->translate('系统充值'); ?></td>
                    <td>
                        <?php
                        if($log_value['pay_state'] == 10) echo $this->translate('未完成').'&nbsp;<a href="'.$this->url('frontmoney/default/paycheck_id', array('action'=>'paycheckPay', 'paycheck_id'=>$log_value['paycheck_id'])).'" class="btn btn-primary">'.$this->translate('去支付').'</a>';
                        if($log_value['pay_state'] == 20) echo '<font color="green">'.$this->translate('已完成').'</font>';
                        ?>
                    </td>
                    <td>
                        <?php
                        if(!empty($log_value['admin_id']) and $log_value['admin_id'] != 0) echo '<strong>'.$this->translate('管理员').'</strong>';
                        else echo $log_value['user_name'];
                        ?>
                    </td>
                    <td>
                        <?php echo !empty($log_value['paycheck_finish_time']) ? date("Y-m-d H:i:s", $log_value['paycheck_finish_time']) : ''; ?></td>
                    </td>
                    <td><?php echo $this->escapeHtml($log_value['paycheck_info']); ?></td>
                </tr>
            <?php } ?>
        </table>
        <div class="page-nav"><?php echo ( count($this->user_paycheck_log) > 0 ) ? $this->paginationControl($this->user_paycheck_log, 'Sliding', 'site/dbpage',array('page_url'=>$this->url('frontmoney/default', $this->page_action))) : ""; ?></div>

        <?php } else { echo '<p>' . $this->translate('暂无记录！') . '</p>'; } ?>
    </div>
</div>
<?php if($yezfState == 1) { ?>
<form method="post" class="simple" id="user_pay_form" style="display: none;" novalidate="true">
    <table class="form">
        <tbody>
        <tr>
            <td class="label"><?php echo $this->translate('选择支付方式'); ?><span class="must_add_value">*</span>：</td>
            <td>
                <select name="payment_code" id="payment_code" class="span2">
                    <?php
                    if($this->payment) {
                        foreach($this->payment as $pay_value) {
                            ?>
                            <option value="<?php echo $pay_value['editaction']; ?>"><?php echo $this->escapeHtml($pay_value['payment_name']['content']); ?></option>
                        <?php } } ?>
                </select>
            </td>
        </tr>
        <tr>
            <td class="label"><?php echo $this->translate('填写充值金额'); ?><span class="must_add_value">*</span>：</td>
            <td><input type="text" value="" name="pay_change_num" id="pay_change_num"></td>
        </tr>
        <tr>
            <td colspan="2"><button type="submit" id="address_add_submit" class="btn" style="margin-left: 150px;"><?php echo $this->translate('立刻充值'); ?></button></td>
        </tr>
        </tbody></table>
</form>
<?php } ?>
<form method="post" class="simple" id="user_money_form" style="display: none;" novalidate="true">
    <table class="form">
        <tbody>
        <tr>
            <td class="label" style="width: 150px;"><?php echo $this->translate('可提现金额'); ?><span class="must_add_value">*</span>：</td>
            <td style="color: red;"><?php echo $this->frontwebsite()->shopPriceExtend($this->user_info->user_money); ?></td>
        </tr>
        <tr>
            <td class="label"><?php echo $this->translate('提现金额'); ?><span class="must_add_value">*</span>：</td>
            <td><input type="text" value="" name="money_change_num" id="money_change_num"></td>
        </tr>
        <tr>
            <td class="label"><?php echo $this->translate('支付名称/开户银行'); ?><span class="must_add_value">*</span>：</td>
            <td><input type="text" value="" name="bank_name" id="bank_name" ></td>
        </tr>
        <tr>
            <td class="label"><?php echo $this->translate('账户名称/开户名称'); ?><span class="must_add_value">*</span>：</td>
            <td><input type="text" value="" name="bank_account" id="bank_account"></td>
        </tr>
        <tr>
            <td class="label"><?php echo $this->translate('账号/卡号'); ?><span class="must_add_value">*</span>：</td>
            <td><input type="text" value="" name="bank_card_number" id="bank_card_number"></td>
        </tr>
        <tr>
            <td colspan="2"><button type="submit" id="address_add_submit" class="btn" style="margin-left: 150px;"><?php echo $this->translate('保存修改'); ?></button></td>
        </tr>
        </tbody></table>
</form>

<script>
    $(document).ready(function() {
        <?php if($yezfState == 1) { ?>
        $("#user_pay_form").validate({
            rules: {
                pay_change_num: {
                    required: true,
                    number: true,
                    min: 1
                },
                payment_code: {
                    required: true
                }
            },
            messages: {
                pay_change_num: {
                    required: "<?php echo $this->translate('充值金额不能为空！'); ?>",
                    number: "<?php echo $this->translate('充值金额必须为数字！'); ?>",
                    min: "<?php echo $this->translate('充值金额最小为 1'); ?>"
                },
                payment_code: {
                    required: "<?php echo $this->translate('请选择支付方式'); ?>"
                }
            },
            submitHandler:function(form){
                to_pay_oper();
            }
        });
        <?php } ?>
        $("#user_money_form").validate({
            rules: {
                money_change_num: {
                    required: true,
                    number: true,
                    min: 0.01,
                    max: <?php echo $this->frontwebsite()->shopPrice($this->user_info->user_money); ?>
                },
                bank_name: {
                    required: true
                },
                bank_account: {
                    required: true
                },
                bank_card_number: {
                    required: true
                }
            },
            messages: {
                money_change_num: {
                    required: "<?php echo $this->translate('提现金额不能为空！'); ?>",
                    number: "<?php echo $this->translate('提现金额必须为数字！'); ?>",
                    min: "<?php echo $this->translate('提现金额最小为 0.01'); ?>",
                    max: "<?php echo $this->translate('提现金额最大为 ').$this->frontwebsite()->shopPrice($this->user_info->user_money); ?>"
                },
                bank_name: {
                    required: "<?php echo $this->translate('支付名称/开户银行 不能为空！'); ?>"
                },
                bank_account: {
                    required: "<?php echo $this->translate('账户名称/开户名称 不能为空！'); ?>"
                },
                bank_card_number: {
                    required: "<?php echo $this->translate('账号/卡号 不能为空！'); ?>"
                }
            },
            submitHandler:function(form){
                save_money_oper();
            }
        });
    });
    <?php if($yezfState == 1) { ?>
    //充值操作
    function my_pay_to() {
        dlg = dialog({id:'user_pay_form',opacity:0.3,padding:'20px 10px 10px 20px',width:900,title:'<?php echo $this->translate('账户充值操作'); ?>',content:document.getElementById('user_pay_form'),lock:true});
        dlg.showModal();
    }
    //充值处理
    function to_pay_oper() {
        var pay_name = $("#payment_code").find("option:selected").text();
        $("#pay_name").val(pay_name);

        $.post("<?php echo $this->url('frontmoney/default', array('action'=>'mypayto')); ?>",$('#user_pay_form').formSerialize(),
            function(data){
                if(data.state == 'true') {
                    window.location.href= data.pay_url;
                } else {
                    art.dialog.tips("<p class='warning'>"+data.message+"</p>");
                    return false;
                }
            }, 'json');
    }
    <?php } ?>
    //提现操作
    function money_oper() {
        $.post("<?php echo $this->url('frontmoney/default', array('action'=>'infowithdraw')); ?>",{},
            function(data){
                if(data == 'true') {
                    dlg = dialog({id:'user_money_form',opacity:0.3,padding:'20px 10px 10px 20px',width:900,title:'<?php echo $this->translate('余额提现操作'); ?>',content:document.getElementById('user_money_form'),lock:true});
                    dlg.showModal();
                } else {
                    art.dialog.tips("<p class='warning'>"+data+"</p>");
                    return false;
                }
            });
    }
    //提现处理
    function save_money_oper() {
        $.post("<?php echo $this->url('frontmoney/default', array('action'=>'addwithdraw')); ?>",$('#user_money_form').formSerialize(),
            function(data){
                if(data == 'true') {
                    window.location.href="<?php echo $this->url('frontmoney/default', array('action'=>'withdrawlog')); ?>";
                } else {
                    art.dialog.tips("<p class='warning'>"+data+"</p>");
                    return false;
                }
            });
    }
</script>